﻿using System;
using System.Reflection;
using System.Configuration;
using Best.Framework.IDAL;
namespace Best.Framework.DALFactory
{
	/// <summary>
	/// 抽象工厂模式创建DAL。
	/// web.config 需要加入配置：(利用工厂模式+反射机制+缓存机制,实现动态创建不同的数据层对象接口) 
	/// DataCache类在导出代码的文件夹里
	/// <appSettings> 
    /// <add key="DAL" value="DQYT.HTDZ.OracleDAL" /> (这里的命名空间根据实际情况更改为自己项目的命名空间)
	/// </appSettings> 
	/// </summary>
	public sealed class DataAccess
	{
		private static readonly string AssemblyPath = ConfigurationManager.AppSettings["DAL"];

        /// <summary>
        /// 创建对象或从缓存获取
        /// </summary>
        public static object CreateObject(string AssemblyPath, string ClassNamespace)
        {
            object objType = DataCache.GetCache(ClassNamespace);//从缓存读取
            if (objType == null)
            {
                try
                {
                    objType = Assembly.Load(AssemblyPath).CreateInstance(ClassNamespace);//反射创建
                    DataCache.SetCache(ClassNamespace, objType);// 写入缓存
                }
                catch
                { }
            }
            return objType;
        }


		/// <summary>
		/// 创建FUJIAN数据层接口。附件表是存储一些像图片
		/// </summary>
		public static DQYT.HTDZ.IDAL.IFUJIAN CreateFUJIAN()
		{

            string ClassNamespace = AssemblyPath + ".FUJIANDAL";
			object objType=CreateObject(AssemblyPath,ClassNamespace);
			return (DQYT.HTDZ.IDAL.IFUJIAN)objType;
		}


		/// <summary>
		/// 创建BDZDJY数据层接口。诊断建议表系统通过工况数据得出的一些诊断建议
		/// </summary>
		public static DQYT.HTDZ.IDAL.IBDZDJY CreateBDZDJY()
		{

            string ClassNamespace = AssemblyPath + ".BDZDJYDAL";
			object objType=CreateObject(AssemblyPath,ClassNamespace);
			return (DQYT.HTDZ.IDAL.IBDZDJY)objType;
		}


		/// <summary>
		/// 创建BDVALUE数据层接口。特征值数据表采集数据的基础上转换后得到的数据
		/// </summary>
		public static DQYT.HTDZ.IDAL.IBDVALUE CreateBDVALUE()
		{

            string ClassNamespace = AssemblyPath + ".BDVALUEDAL";
			object objType=CreateObject(AssemblyPath,ClassNamespace);
			return (DQYT.HTDZ.IDAL.IBDVALUE)objType;
		}


		/// <summary>
		/// 创建BDPULL数据层接口。抽油机表油井上采油的机器
		/// </summary>
		public static DQYT.HTDZ.IDAL.IBDPULL CreateBDPULL()
		{

            string ClassNamespace = AssemblyPath + ".BDPULLDAL";
			object objType=CreateObject(AssemblyPath,ClassNamespace);
			return (DQYT.HTDZ.IDAL.IBDPULL)objType;
		}


		/// <summary>
		/// 创建BDPOVERMACHINE数据层接口。电机表抽油机上的电机
		/// </summary>
		public static DQYT.HTDZ.IDAL.IBDPOVERMACHINE CreateBDPOVERMACHINE()
		{

            string ClassNamespace = AssemblyPath + ".BDPOVERMACHINEDAL";
			object objType=CreateObject(AssemblyPath,ClassNamespace);
			return (DQYT.HTDZ.IDAL.IBDPOVERMACHINE)objType;
		}


		/// <summary>
		/// 创建BDJTWELL数据层接口。单井静态数据表指油田上的井的一些静态参数数据
		/// </summary>
		public static DQYT.HTDZ.IDAL.IBDJTWELL CreateBDJTWELL()
		{

            string ClassNamespace = AssemblyPath + ".BDJTWELLDAL";
			object objType=CreateObject(AssemblyPath,ClassNamespace);
			return (DQYT.HTDZ.IDAL.IBDJTWELL)objType;
		}


		/// <summary>
		/// 创建BDGQ数据层接口。工区表存放物探工区、
		/// </summary>
		public static DQYT.HTDZ.IDAL.IBDGQ CreateBDGQ()
		{

            string ClassNamespace = AssemblyPath + ".BDGQDAL";
			object objType=CreateObject(AssemblyPath,ClassNamespace);
			return (DQYT.HTDZ.IDAL.IBDGQ)objType;
		}


		/// <summary>
		/// 创建BDELEBOX数据层接口。配电柜表抽油机上的配
		/// </summary>
		public static DQYT.HTDZ.IDAL.IBDELEBOX CreateBDELEBOX()
		{

            string ClassNamespace = AssemblyPath + ".BDELEBOXDAL";
			object objType=CreateObject(AssemblyPath,ClassNamespace);
			return (DQYT.HTDZ.IDAL.IBDELEBOX)objType;
		}


		/// <summary>
		/// 创建BDDTWELL数据层接口。单井动态数据表指油田上的井的一些动态参数数据
		/// </summary>
		public static DQYT.HTDZ.IDAL.IBDDTWELL CreateBDDTWELL()
		{

            string ClassNamespace = AssemblyPath + ".BDDTWELLDAL";
			object objType=CreateObject(AssemblyPath,ClassNamespace);
			return (DQYT.HTDZ.IDAL.IBDDTWELL)objType;
		}


		/// <summary>
		/// 创建BDDATESOURSE数据层接口。采集数据表项目中采集
		/// </summary>
		public static DQYT.HTDZ.IDAL.IBDDATESOURSE CreateBDDATESOURSE()
		{

            string ClassNamespace = AssemblyPath + ".BDDATESOURSEDAL";
			object objType=CreateObject(AssemblyPath,ClassNamespace);
			return (DQYT.HTDZ.IDAL.IBDDATESOURSE)objType;
		}


		/// <summary>
		/// 创建BDDICT数据层接口。
		/// </summary>
        public static DQYT.HTDZ.IDAL.IBDDICT CreateBDDICT()
		{

			string ClassNamespace = AssemblyPath +".BDDICTDAL";
			object objType=CreateObject(AssemblyPath,ClassNamespace);
			return (DQYT.HTDZ.IDAL.IBDDICT)objType;
		}


		/// <summary>
		/// 创建BDDATATABLE数据层接口。
		/// </summary>
		public static DQYT.HTDZ.IDAL.IBDDATATABLE CreateBDDATATABLE()
		{

			string ClassNamespace = AssemblyPath +".BDDATATABLEDAL";
			object objType=CreateObject(AssemblyPath,ClassNamespace);
			return (DQYT.HTDZ.IDAL.IBDDATATABLE)objType;
		}

        /// <summary>
        /// 创建部门数据层接口
        /// </summary>
        /// <returns></returns>
        public static DQYT.HTDZ.IDAL.IBDDepartment CreateBDDepartment()
        {

            string ClassNamespace = AssemblyPath + ".BDDepartmentDAL";
            object objType = CreateObject(AssemblyPath, ClassNamespace);
            return (DQYT.HTDZ.IDAL.IBDDepartment)objType;
        }

        /// <summary>
        /// 创建菜单数据层接口
        /// </summary>
        /// <returns></returns>
        public static DQYT.HTDZ.IDAL.IBDMenu CreateBDMenu()
        {

            string ClassNamespace = AssemblyPath + ".BDMenuDAL";
            object objType = CreateObject(AssemblyPath, ClassNamespace);
            return (DQYT.HTDZ.IDAL.IBDMenu)objType;
        }

        /// <summary>
        /// 创建角色数据层接口
        /// </summary>
        /// <returns></returns>
        public static DQYT.HTDZ.IDAL.IBDRole CreateBDRole()
        {

            string ClassNamespace = AssemblyPath + ".BDRoleDAL";
            object objType = CreateObject(AssemblyPath, ClassNamespace);
            return (DQYT.HTDZ.IDAL.IBDRole)objType;
        }

        /// <summary>
        /// 创建角色菜单数据层接口
        /// </summary>
        /// <returns></returns>
        public static DQYT.HTDZ.IDAL.IBDRoleMenu CreateBDRoleMenu()
        {

            string ClassNamespace = AssemblyPath + ".BDRoleMenuDAL";
            object objType = CreateObject(AssemblyPath, ClassNamespace);
            return (DQYT.HTDZ.IDAL.IBDRoleMenu)objType;
        }

        /// <summary>
        /// 创建用户数据层接口
        /// </summary>
        /// <returns></returns>
        public static DQYT.HTDZ.IDAL.IBDUser CreateBDUser()
        {

            string ClassNamespace = AssemblyPath + ".BDUserDAL";
            object objType = CreateObject(AssemblyPath, ClassNamespace);
            return (DQYT.HTDZ.IDAL.IBDUser)objType;
        }
       
}
}